package com.le.tester.javaThink.fifth.chapter14_StreamingProgramming;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

/**
 * 描述：文件转换成word
 */
public class FileToWordsBuilder {
    Stream.Builder<String> builder = Stream.builder();

    public FileToWordsBuilder(String filePath) throws IOException {
        Files.lines(Paths.get(filePath))
                .skip(1).forEach(o -> {
            for (String w : o.split("[ .?,]+")) {
                builder.add(w);
            }
        });
    }

    Stream<String> stream() {
        return builder.build();
    }

    public static void main(String[] args) throws IOException {
        new FileToWordsBuilder("E:\\L.info\\L.Application\\L.Tester\\src\\main\\java\\com\\le\\tester\\java8\\doc\\Cheese.dat")
                .stream().limit(7).map(o -> o + " ")
                .forEach(System.out::println);
    }
}
